import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './filter/httpException/httpException';
import { ResponseInterceptor } from './interceptor/response';
import { LoggerInterceptor } from './interceptor/logger';
import { ValidationPipe } from './validate.pipe';
import rateLimit from 'express-rate-limit';
import * as express from 'express';
//import * as csurf from 'csurf';
import { SwaggerModule } from '@nestjs/swagger';
import { options } from './swagger_config/config';
import { logger } from './middleWare/logger/Logger.MiddleWare';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('api', app, document);
  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalInterceptors(new LoggerInterceptor());
  app.useGlobalInterceptors(new ResponseInterceptor());
  app.use(express.urlencoded({ extended: true })); 
  app.use(logger);
  //app.use(csurf());
  app.use(
    rateLimit({
      windowMs: 1000, // 1 second
      max: 10, // limit each IP to 100 requests per windowMs
    })
  );
  app.enableCors();
  await app.listen(3000);
}
bootstrap();
